# TODO:待跑通
import subprocess
import datetime
import os


date = datetime.datetime.now().strftime('%Y-%m-%d')


backup_dir = '/path/to/your/backup/directory'  # 修改为你想要保存备份的目录
filename = 'backup-{}.sql'.format(date)

command = ['mysqldump', '-u', 'root', '-p', 'myblog', '--result-file={}'.format(filename)]

try:
    subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    print("备份成功！")
except subprocess.CalledProcessError as e:
    print("备份失败:", e)